package org.example.config.interceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public UserInteceptor userInteceptor() {
        return new UserInteceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userInteceptor())
                .addPathPatterns("/**")       // 拦截所有请求
                .excludePathPatterns("/user/register", "/user/**", "/login/oauth2/code/github", "/doc.html/**",
                        "/webjars/**",
                        "/v3/api-docs/**",
                        "/v3/api-docs/swagger-config"); // 排除登录接口
    }
}
